package com.vhuomai.product.label.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.product.label.entity.BaseLabelCategory;
import com.vhuomai.product.label.mapper.LabelCategoryMapper;
import com.vhuomai.product.label.service.LabelCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class LabelCategoryServiceImpl implements LabelCategoryService {
    @Autowired
    private LabelCategoryMapper categoryMapper;

    @Override
    public void createCategory(BaseLabelCategory category) {
        category.setId(null);
        category.setMerchantNo(GlobalContext.merchantNo());
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.insert(category);
    }

    @Override
    public void updateCategory(BaseLabelCategory category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.updateSelective(category);
    }

    @Override
    public void deleteCategory(Integer categoryId) {
        categoryMapper.deleteOne(categoryId);
    }

    @Override
    public List<BaseLabelCategory> findCategorys() {
        return categoryMapper.findByMerchantNo(GlobalContext.merchantNo());
    }
}
